const webpackMerge = require('webpack-merge');
const baseConfig = require('./webpack.base');
// const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const path = require('path');
// const smp = new SpeedMeasurePlugin();

const DIST_PATH = path.resolve(__dirname, '../', 'dist');
const config = {
    mode: 'development',
    cache: {type: 'filesystem'},
    devtool: 'eval-cheap-module-source-map',
    stats: 'errors-only',
    plugins: [new ReactRefreshWebpackPlugin()].filter(Boolean),
    watchOptions: {
        aggregateTimeout: 500,
        poll: 1000,
        ignored: /node_modules/,
    },
    devServer: {
        open: 'chrome',
        contentBase: DIST_PATH,
        compress: true, //是否启用gzip压缩
        publicPath: '/',
        host: 'localhost',
        port: 3000,
        hot: true,
        disableHostCheck: true,
        stats: 'errors-only',
        historyApiFallback: {
            disableDotRule: true, // react-router-dom v6 使用BrowserRouter模式要配置此项
        },
        proxy: {
            // "/api": {
            //     target: "http://localhost:3000"
            // }
        },
    },
};
const mergedConfig = webpackMerge.merge(baseConfig, config);
// 配置了 SpeedMeasurePlugin 后，热更新就无效了，会提示 runtime is undefined。
// module.exports = smp.wrap({
//     ...mergedConfig,
// });

module.exports = mergedConfig;
